package site.marqstree.latte.ec.main.personal.profile;

/*
 * 项目名: EleCommerce
 * 包名: site.marqstree.latte.ec.main.personal.profile
 * 文件名: UserProfileDelegate
 * 创建者: marqstree
 * 创建时间: 2020/2/4 8:57
 * 描述: TODO
 */

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import site.marqstree.latte.core.delegates.LatteDelegate;
import site.marqstree.latte.ec.R;
import site.marqstree.latte.ec.R2;
import site.marqstree.latte.ec.main.personal.list.ListAdapter;
import site.marqstree.latte.ec.main.personal.list.ListBean;
import site.marqstree.latte.ec.main.personal.list.ListItemType;
import site.marqstree.latte.ec.profile.AppProfile;

public class UserProfileDelegate extends LatteDelegate {

    final ListAdapter mAdapter = new ListAdapter();

    @BindView(R2.id.rv_user_profile)
    RecyclerView mRecyclerView = null;

    @Override
    public Object setLayout() {
        return R.layout.delegate_user_profile;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        final ListBean image = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_AVATAR)
                .setId(1)
                .setImageUrl(AppProfile.AVATAR_URL)
                .build();

        final ListBean name = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_NORMAL)
                .setId(2)
                .setText("姓名")
                .setDelegate(new NameDelegate())
                .setValue("未设置姓名")
                .build();

        final ListBean gender = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_NORMAL)
                .setId(3)
                .setText("性别")
                .setValue("未设置性别")
                .build();

        final ListBean birth = new ListBean.Builder()
                .setItemType(ListItemType.ITEM_NORMAL)
                .setId(4)
                .setText("生日")
                .setValue("未设置生日")
                .build();

        final List<ListBean> data = new ArrayList<>();
        data.add(image);
        data.add(name);
        data.add(gender);
        data.add(birth);

        //设置RecyclerView
        final LinearLayoutManager manager = new LinearLayoutManager(getContext());
        mRecyclerView.setLayoutManager(manager);
        mRecyclerView.setAdapter(mAdapter);

        // 设置点击事件
        mAdapter.setOnItemClickListener(new UserProfileItemClickListener(this));

        mAdapter.setNewData(data);
    }
}